<%@ page language="java" import="java.util.*" pageEncoding="utf-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- ssx --%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath %>">
<title>供应商信息管理</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<%-- 引用layui.css --%>
<link rel="stylesheet" type="text/css" href="<%=basePath %>js/layui/css/layui.css" />
<link rel="stylesheet" type="text/css"href="<%=basePath %>css/common.css" />
</head>
<body>
	<div class="ibox">
		<div class="ibox-content bodycss">
			<!-- 表单搜索 开始 -->
		 	<section class="panel panel-padding ">
			<form class="layui-form layui-form-pane form-search"
				onsubmit="return false" method="get">
				
				<div class="layui-form-item layui-inline">
					<label class="layui-form-label">供应商名称</label>
					<div class="layui-input-inline">
						<input name="supplierName" id="supplierName" value="" placeholder="请输入名称"
							class="layui-input">
					</div>
				</div>
				<div class="layui-form-item layui-inline">
					<label class="layui-form-label">供应商电话</label>
					<div class="layui-input-inline">
						<input name="contactsPhone" id="contactsPhone" value="" placeholder="请输入电话"
							class="layui-input">
					</div>
				</div>				
				<div class="layui-form-item layui-inline">
					<label class="layui-form-label">供应商状态</label>
					<div class="layui-input-inline" >
					  <div  style="width:150px">
						<select name="supplierStatus" id="supplierStatus" > <!-- 状态：0:禁用  1：启用 -->
							<option value="">请选择</option>
							<option value="0">已禁用</option>
							<option value="1">已启用</option>
						</select>
                      </div>
					</div>
				</div>
				<div class="layui-form-item layui-inline">
					<button class="layui-btn layui-btn-primary" lay-submit lay-filter="seach">
						<i class="layui-icon"></i> 搜 索
					</button>
				</div>
			</form>
			</section>
			
			
			
			<!-- 表单搜索 结束 -->
			<section class="panel panel-padding ">
			
			  <div class="layui-btn-container">
			    <button class="layui-btn layui-btn-sm" id="adds">新增信息</button>
			    <button class="layui-btn layui-btn-sm" id="deletes">批量删除</button>
			  </div>
            
			<table class="layui-table"
			       
				lay-data="{
	                        id:'menuTeble',
	                        width:'auto',
	                        url:'supplier/list.do',
	                        page:true,
	                        even:true,
	                        skin:'row',
	                        limits:[10,20,30,40,50],
	                        limit:10}"
				lay-filter="popedomLay"
				
				>
				
				<thead >
					<tr>
						<th lay-data="{checkbox:true,disabledKey:'check_status',disabledKeyValue:'1,2'}"></th>
						<th lay-data="{type:'numbers', width:50}">序号</th>
						<!-- <th lay-data="{field:'supplierId', width:120,align:'center'}">供应商ID</th> -->
						<th lay-data="{field:'supplierName', width:120,align:'center'}">供应商名称</th>
						<th lay-data="{field:'contactsName', width:200,align:'center'}">联系人姓名</th>
						<th lay-data="{field:'contactsPhone', width:120,align:'center'}">供应商电话</th>
						<th lay-data="{field:'supplierCode', width:200,align:'center'}">供应商编码</th>
						<th lay-data="{field:'postalCode', width:200,align:'center'}">邮编</th>
						<th lay-data="{field:'supplierAdderss', width:200,align:'center'}">供应商详细地址</th>
						<th lay-data="{field:'remarks', width:200,align:'center'}">供应商描述</th>
						<th lay-data="{field:'createTime', width:200,align:'center'}">创建时间</th>
                   <!-- <th lay-data="{field:'sort', width:200,align:'center'}">顺序</th> -->
						<th lay-data="{field:'supplierStatus', width:120,align:'center',templet:'#m_type'}">状态</th>
						<th lay-data="{fixed: 'right', width:350, align:'center', toolbar: '#popedomBar'}">操作</th>
					</tr>
				</thead>
				
			</table>
			
			</section>
		</div>
	</div>
	

	
	<script type="text/html" id="m_type">	
		{{# if(d.supplierStatus == "0") {  }}
			<font color="#ff0000">已禁用</font>
        {{#  } else if(d.supplierStatus == "1") {  }}
			<font color="#393D49">已启用</font>
		{{#  }  }}
    </script><!--  -->
	<script type="text/html" id="popedomBar">
			<a class="layui-btn layui-bg-blue layui-btn-xs" lay-event="deitPw"  >修改状态</a>
            <a class="layui-btn layui-bg-cyan layui-btn-xs"  lay-event="edit" >修改信息</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs"  lay-event="del" >删除信息</a>
    </script>
	<script type="text/javascript" src="<%=basePath %>js/layui/layui.js"></script>
	<script type="text/javascript">
	
	layui.config({
	    base: "<%=basePath%>/js/common/"
	}).use(["common", "element", "layer", "form", "table", "jquery"], function(){
			var elem = layui.element;
			var layer = layui.layer;
			var form = layui.form;
			var table = layui.table;
			var $ = layui.jquery;
			layui.common.init();			
			/**
			 * 监听刷新表格
			 */
		form.on('submit(seach)', function(data){
			console.log(JSON.stringify(data.field));
			table.reload('menuTeble', {
				where: data.field,
				page : {
					curr : 1
				}
			});
			return false;
		});
		
		
		/*
		     监听行事件
		
		**/	
		 table.on('tool(popedomLay)', function(obj){
			    var data = obj.data;
			    var supplierId = data.supplierId;
			    var supplierStatus = data.supplierStatus;
			    //console.log(supplierStatus)
			    if(obj.event === 'del'){
			      layer.confirm('真的删除行么', function(index){
			        obj.del();
			        layer.close(index);
			        
			        $.ajax({
			        	url: "supplier/delete.do",
			        	method:"post",
			        	data:{
			        	"supplierId" : supplierId	
			        	}	
			        })
			        
			      });
			    } else if(obj.event === 'edit'){
			    	layer.open({
	                    type: 2,
	                    title: '修改用户信用信息',
	                    content: 'supplier/updates.do',
	                    area: ['650px', '500px'],
	                    anim: 5,
	                    isOutAnim: true,
	                    maxmin: true,
	                    resize: false,
	                    moveOut: true,
	                    zIndex: 99999,
	                    success: function(layero, index){
	                    	var body = layer.getChildFrame('body', index);
	                    	body.contents().find("INPUT[name='supplierId']").val(data.supplierId);
	                    	body.contents().find("INPUT[name='supplierName']").val(data.supplierName);
	                        body.contents().find("INPUT[name='contactsName']").val(data.contactsName);
	                        body.contents().find("INPUT[name='contactsPhone']").val(data.contactsPhone);
	                        body.contents().find("INPUT[name='supplierCode']").val(data.supplierCode);
	                        body.contents().find("INPUT[name='postalCode']").val(data.postalCode);
	                        body.contents().find("TEXTAREA[name='supplierAdderss']").val(data.supplierAdderss);
	                        body.contents().find("TEXTAREA[name='remarks']").val(data.remarks); 
	                        body.contents().find("INPUT[name='supplierStatus']").val(data.supplierStatus);
	                    },
	                    end : function(){
	                    	table.reload("menuTeble");
	                    }

			    	});
			    }else if(obj.event === 'deitPw'){
		    	layer.confirm('确定修改状态？', function(index){
			        //obj.del();
			        layer.close(index);
			        $.ajax({
			        	url: "supplier/update.do",
			        	method:"post",
			        	data:{
			        	"supplierId" : supplierId,
			        	"supplierStatus" : supplierStatus	
			        	},
			        success : function (data){
						table.reload('menuTeble',{
							where : data.field
						})
					}
			        })
			        //location.reload();   
				  })
				}
			  });
		
		 
 
		        
			//新增
			 $('#adds').on('click', function(){
				 var that = this; 
					layer.open({
				        type: 2 
				        ,title: '新增'
				        ,area: ['650px', '450px']
				        ,shade: 0
				        ,maxmin: true
				        ,content: 'supplier/adds.do'
					})
				});
			

		
			//批量删除
			 $('#deletes').on('click', function(data){
				  //active.deletes();
				  var checkStatus = table.checkStatus('menuTeble');
				  var data = checkStatus.data;
				   data = JSON.stringify(data);
				  //console.log(data);
				  //var supplierId=$.map(data,function(d){return d.supplierId;});
				  //console.log(JSON.stringify(supplierId));
				  //console.log(JSON.stringify(data));
				  
				   layer.confirm('真的删除么', function(index){
			        
			        layer.close(index);
				  
				   $.ajax({
			        	url: "supplier/deletes.do?data="+data,
			        	method:"post",
			        //	contentType: 'application/json; charset=UTF-8',
			        //	dataType:"json",
			        //	data:data,
			        
			        //小范围刷新	
			        success : function (data){
						table.reload('menuTeble',{
							where : data.field
						})
					}
			        })
				   
				   });
				   
				}); 
			
		       
	});
</script>

</body>
</html>
